<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-lg-10">
        <h2>{$label}列表</h2>
        <ol class="breadcrumb">
            <li>
                <a href="{:url('admin/index/index')}">控制台</a>
            </li>
            <li class="active">
                <strong>查看列表</strong>
            </li>
        </ol>
    </div>
    <div class="col-lg-2">
        {if condition="$buttons['create'] eq 1"}
        <h2><a href="{:url('admin/'.$route.'/create')}" class="btn btn-success" type="button"><i class="fa fa-plus"></i> 新增</a></h2>
        {/if}
    </div>
</div>
<div class="wrapper wrapper-content animated ">
    <!--<div class="wrapper wrapper-content animated ">-->
    <div class="row">
        <div class="col-lg-12">
            <div class="ibox float-e-margins">
                <div class="ibox-content">
                    <div class="row">
                        <div class="col-sm-5 m-b-xs">

                        </div>
                        <!--<div class="col-sm-3" style="float: right">-->
                        <!--<div class="input-group"><input type="text" placeholder="Search" class="input-sm form-control"> <span class="input-group-btn">-->
                        <!--<button type="button" class="btn btn-sm btn-primary"> Go!</button> </span></div>-->
                        <!--</div>-->
                    </div>
                    <table class="table table-hover" id="list">
                        <thead>
                        <tr>
                            {if condition="$buttons['delete'] eq 1"}<th>选择</th>{/if}
                            <th>#</th>
                            <th>菜单名</th>
                            <!--<th>图标</th>-->
                            <th>链接</th>
                            <th>排序</th>
                            <th>添加时间</th>
                            <th width="150">操作</th>
                            <div style="clear:both;"></div>
                        </tr>
                        </thead>
                        <tbody>
                        {empty name="list"}<tr><td style="text-align: center" colspan="8">暂无数据</td></tr>{/empty}
                        {foreach $list as $v}
                        <tr>
                            {if condition="$buttons['delete'] eq 1"}<td><input type="checkbox" value="{$v['id']}" class="ids"></td>{/if}
                            <td>{$v.id}</td>
                            <td>{$v.name}</td>
                            <!--<td>{$v.icon}</td>-->
                            <td>{$v.url}</td>
                            <td>{$v.sort}</td>
                            <td>{$v.created_at}</td>
                            <td>
                                {if condition="$buttons['edit'] eq 1"}
                                <a href="{:url('/admin/'.$route.'/'.$v['id'].'/edit')}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 编辑</a>
                                {/if}
                                {if condition="$buttons['delete'] eq 1"}
                                <a onclick="del({$v['id']})" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a>
                                {/if}
                            </td>
                        </tr>
                        {foreach $v['child'] as $_v}
                        <tr>
                            {if condition="$buttons['delete'] eq 1"}<td><input type="checkbox" value="{$_v['id']}" class="ids"></td>{/if}
                            <td>{$_v.id}</td>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;├─ {$_v.name}</td>
                            <!--<td>{$_v.icon}</td>-->
                            <td>{$_v.url}</td>
                            <td>{$_v.sort}</td>
                            <td>{$_v.created_at}</td>
                            <td>
                                {if condition="$buttons['edit'] eq 1"}
                                <a href="{:url('/admin/'.$route.'/'.$_v['id'].'/edit')}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 编辑</a>
                                {/if}
                                {if condition="$buttons['delete'] eq 1"}
                                <a onclick="del({$_v['id']})" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a>
                                {/if}
                            </td>
                        </tr>
                        {foreach $_v['child'] as $__v}
                        <tr>
                            {if condition="$buttons['delete'] eq 1"}<td><input type="checkbox" value="{$__v['id']}" class="ids"></td>{/if}
                            <td>{$__v.id}</td>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;├─ {$__v.name}</td>
                            <!--<td>{$__v.icon}</td>-->
                            <td>{$__v.url}</td>
                            <td>{$__v.sort}</td>
                            <td>{$__v.created_at}</td>
                            <td>
                                {if condition="$buttons['edit'] eq 1"}
                                <a href="{:url('/admin/'.$route.'/'.$__v['id'].'/edit')}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 编辑</a>
                                {/if}
                                {if condition="$buttons['delete'] eq 1"}
                                <a onclick="del({$__v['id']})" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a>
                                {/if}
                            </td>
                        </tr>
                        {foreach $__v['child'] as $___v}
                        <tr>
                            {if condition="$buttons['delete'] eq 1"}<td><input type="checkbox" value="{$___v['id']}" class="ids"></td>{/if}
                            <td>{$___v.id}</td>
                            <td>&nbsp;&nbsp;&nbsp;&nbsp;│&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;├─ {$___v.name}</td>
                            <!--<td>{$___v.icon}</td>-->
                            <td>{$___v.url}</td>
                            <td>{$___v.sort}</td>
                            <td>{$___v.created_at}</td>
                            <td>
                                {if condition="$buttons['edit'] eq 1"}
                                <a href="{:url('/admin/'.$route.'/'.$___v['id'].'/edit')}" class="btn btn-primary btn-xs"><i class="fa fa-edit"></i> 编辑</a>
                                {/if}
                                {if condition="$buttons['delete'] eq 1"}
                                <a onclick="del({$___v['id']})" class="btn btn-danger btn-xs"><i class="fa fa-trash"></i> 删除</a>
                                {/if}
                            </td>
                        </tr>
                        {/foreach}
                        {/foreach}
                        {/foreach}
                        {/foreach}
                        </tbody>
                    </table>
                    {if condition="$buttons['delete'] eq 1"}
                    <label><input type="checkbox" class="all"> 全选</label> &nbsp;&nbsp;&nbsp;<button class="btn btn-danger btn-sm" id="del-all">删除</button>
                    {/if}
                </div>
            </div>
        </div>
        <script>
            function del(id) {
                layer.confirm('你确认删除此条记录吗？', {
                    btn: ['确认','取消']
                }, function(){
                    var index = layer.load(1);
                    $.ajax({
                        type:"DELETE",
                        url:"{:url('/admin/'.$route.'/"+id+"')}",
                        //返回数据的格式
                        datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                        //成功返回之后调用的函数
                        success:function(data){
                            layer.close(index);
                            if (data.status == 1){
                                layer.msg('删除成功', {icon:1, time:600}, function () {
                                    window.location.reload();
                                })
                            }else {
                                layer.msg(data.msg, {icon:2, time:800})
                            }
                        },
                        //调用出错执行的函数
                        error: function(){
                            layer.close(index);
                            layer.alert('系统异常')
                            //请求出错处理
                        }
                    });
                });
            }
            function getValues(){
                var ids = '';

                $("#list :checkbox").each(function(i){
                    if ($(this).is(":checked")){
                        ids += $(this).val()+',';
                    }
                });
                return ids;
            }
        </script>
        <script>
            $(function () {
                //全选或全不选
                $(".all").click(function(){
                    if(this.checked){
                        $("#list :checkbox").prop("checked", true);
                    }else{
                        $("#list :checkbox").prop("checked", false);
                    }
                });

                $('#del-all').click(function () {
                    var id = getValues();
                    if (id == ''){
                        layer.msg('请选择需要删除的记录！');
                        return false;
                    }
                    layer.confirm('你确认删除选择的记录吗？', {
                        btn: ['确认','取消']
                    }, function() {
                        var index = layer.load(1);
                        $.ajax({
                            type: "DELETE",
                            url: "{:url('/admin/'.$route.'/" + id + "')}",
                            //返回数据的格式
                            datatype: "json",//"xml", "html", "script", "json", "jsonp", "text".
                            //成功返回之后调用的函数
                            success: function (data) {
                                layer.close(index);
                                if (data.status == 1) {
                                    layer.msg('删除成功', {icon: 1, time: 600}, function () {
                                        window.location.reload();
                                    })
                                } else {
                                    layer.msg(data.msg, {icon: 2, time: 800})
                                }
                            },
                            //调用出错执行的函数
                            error: function () {
                                layer.close(index);
                                layer.alert('系统异常')
                                //请求出错处理
                            }
                        });
                    })
                })
            });
        </script>
    </div>
</div>